<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="wf" uri="/augurit-wf"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="${ctx}/gzcgwsp/resources/css/common-ui.css" rel="stylesheet" type="text/css" />

<!-- dwr libs -->
<script type='text/javascript' src="${ctx}/dwr/engine.js"></script>
<script type='text/javascript' src="${ctx}/dwr/util.js"></script>
<script type='text/javascript' src="${ctx}/dwr/interface/FileUploadCntl.js"></script>

<script src="${ctx}/gzcgwsp/resources/js/YwUtil.js" type="text/javascript"></script>

<script src="${ctx}/gzcgwsp/resources/js/YwEnterprise.js" type="text/javascript"></script>
<script src="${ctx}/gzcgwsp/resources/js/clxx.js" type="text/javascript"></script>
<script type="text/javascript">

var saveAndSendFlag = undefined;

$(document).ready(function(){
  $('form[0]').ajaxForm({
    dataType: 'json', 
    success: wfBusSaveCallback
  });
});

function wfBusSaveCallback(result){
  var success = window.updateLayoutAfterWfBusSave(result, false);
  
  if(success){
    if (result && result.form) {
      WF_CONFIG.masterEntityKey = result.form.id;
      document.forms[0].id.value = result.form.id;
      document.forms[0].qyid.value = result.form.qyid;
      document.forms[0].acceptNo.value = result.form.acceptNo;
      //document.forms[0].acceptNo_.value = result.form.acceptNo;
      
      document.getElementById('sjcl_iframe').src = '${ctx}/yw-com-sjcllist!ywList.action?tplcode=${templateCode}&ajid=' + result.form.id + '&qyid=' + result.form.qyid;
      
      if (Ext.getCmp('sjclPanel')) Ext.getCmp('sjclPanel').setDisabled(false);
      if (Ext.getCmp('gisPanel')) Ext.getCmp('gisPanel').setDisabled(false);
      
      if (Ext.getCmp('WF_PRINT')) Ext.getCmp('WF_PRINT').setDisabled(false);
      if (Ext.getCmp('clxxPanel')) Ext.getCmp('clxxPanel').setDisabled(false);
      saveOpinion();
    }
    
    if(saveAndSendFlag == 'wfBusSaveAndSend') {
      var toolbar = Ext.getCmp('WF_TOOLBAR');
      if(toolbar) toolbar.wfSend();
    }
    if(saveAndSendFlag == 'wfBusSave') {
      alert('保存成功！');
    }
    if(saveAndSendFlag == 'wfBusSj') {
      if (opener.refresh) opener.refresh();
      Ext.getCmp('YslSjBtn').setDisabled(true);
      Ext.getCmp('YslTuihBtn').setDisabled(true);
      alert('收件成功！');
    }
    if(saveAndSendFlag == 'wfBusYslTuih') {
      if (opener.refresh) opener.refresh();
      window.close();
    }
  }
}

function wfBusSaveAndSend(templateCode, taskInstDbid){
  saveAndSendFlag = 'wfBusSaveAndSend';
  if(validateSend()){
    $('form[0]').attr('action', '${ctx}/yw-yn-ljzyz-shhz!wfBusSave.action?templateCode='+templateCode+'&taskInstDbid='+taskInstDbid);
    $('form[0]').submit();
  }
}

function wfBusSave(templateCode, taskInstDbid){
  saveAndSendFlag = 'wfBusSave';
  if(validateForm()){
    $('form[0]').attr('action', '${ctx}/yw-yn-ljzyz-shhz!wfBusSave.action?templateCode='+templateCode+'&taskInstDbid='+taskInstDbid);
    $('form[0]').submit();
  }
}

function wfBusSj() {
  saveAndSendFlag = 'wfBusSj';
  if(validateForm()){
    $('form[0]').attr('action', '${ctx}/yw-yn-ljzyz-shhz!wfBusSave.action?templateCode='+WF_CONFIG.templateCode+'&isYsl=1');
    $('form[0]').submit();
  }
}

function wfBusYslTuih() {
  saveAndSendFlag = 'wfBusYslTuih';
  if(validateForm()){
    $('form[0]').attr('action', '${ctx}/yw-yn-ljzyz-shhz!wfBusYslTuih.action?templateCode='+WF_CONFIG.templateCode+'&isYsl=1');
    $('form[0]').submit();
  }
}

function CreateDoc(){
  var win = new Ext.ux.wf.WfSelRedHeadFile({
    url: '/yw-yn-ljzyz-shhz!makeDocument.action'
  });
  win.show();
}

function printcz(){
  var busEntityKey = document.forms[0].id.value;
  
  if(busEntityKey != null && busEntityKey != '') {
    var url = '${ctx}/yw-com-print!taskInfo.action?id='+busEntityKey + '&templateCode=' + WF_CONFIG.templateCode;
    YwUtil.openWin({url: url, w: 500, h: 400});
  }
}

function saveOpinion() {
    var jbrxckcTxt = document.getElementById('jbrxckcJudgmentTxt_ynczz');
    var jbhcTxt = document.getElementById('jbhcJudgmentTxt_ynczz');
    var kzTxt = document.getElementById('kzJudgmentTxt_ynczz');

    var fczTxt = document.getElementById('fczJudgmentTxt_ynczz');
    var czTxt= document.getElementById('czJudgmentTxt_ynczz');
    
    
    var inputObj, divobj;
    if (jbrxckcTxt && !jbhcTxt && !kzTxt && !fczTxt && !czTxt) {
      inputObj = jbrxckcTxt; divobj = document.getElementById('jbrxckcJudgment');
    } else if (!jbrxckcTxt && jbhcTxt && !kzTxt && !fczTxt && !czTxt) {
      inputObj = jbhcTxt; divobj = document.getElementById('jbhcJudgment');
    }else if (!jbrxckcTxt && !jbhcTxt && kzTxt && !fczTxt && !czTxt) {
      inputObj = kzTxt; divobj = document.getElementById('kzJudgment');
    }else if (!jbrxckcTxt && !jbhcTxt && !kzTxt && fczTxt && !czTxt) {
      inputObj = fczTxt; divobj = document.getElementById('fczJudgment');
    }else if (!jbrxckcTxt && !jbhcTxt && !kzTxt && !fczTxt && czTxt) {
      inputObj = czTxt; divobj = document.getElementById('czJudgment');
    }
    
    
    if (!inputObj || inputObj.value == '') return;
    
    Ext.Ajax.request({
      method:'post',
      url:'${ctx}/wf!saveTaskOpinion.action',
      params:{
        'instance.taskInstDbid': WF_CONFIG.taskInstDbid,
        'instance.handleComments': inputObj.value
      },
      success:function(){
      changeOpinion(inputobj.value, divobj);
        inputobj.value = '';
      },
      scope:this
    });
}

function writeJudgment(index) {
    var divid = '';
    switch(index) {
        case 'A': divid = 'jbhcJudgment'; break;
        case 'B': divid = 'jbrxckcJudgment'; break;
        case 'C': divid = 'kzJudgment'; break;
        case 'D': divid = 'fczJudgment'; break;
        case 'E': divid = 'czJudgment'; break;
    }
    var divobj = document.getElementById(divid);
    if (divid == '' || !divobj) {
        alert('参数错误！');
        return;
    }
    var win = new Ext.ux.wf.WfOpinionWin({
        taskInstDbid: Ext.getCmp('WF_TOOLBAR').taskInstDbid
    });
    win.show();
    win.on('complete', function (opinion) {
        divobj.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
    });
}

function inputJudgment(index) {
    var divid = '', inputid = '';
    switch(index) {
        case 'A': divid = 'jbhcJudgment'; inputid = 'jbhcJudgmentTxt_ynczz'; break;
        case 'B': divid = 'jbrxckcJudgment'; inputid = 'jbrxckcJudgmentTxt_ynczz'; break;
        case 'C': divid = 'kzJudgment'; inputid = 'kzJudgmentTxt_ynczz'; break;
        case 'D': divid = 'fczJudgment'; inputid = 'fczJudgmentTxt_ynczz'; break;
        case 'E': divid = 'czJudgment'; inputid = 'czJudgmentTxt_ynczz'; break;
    }
    var divobj = document.getElementById(divid);
    var inputobj = document.getElementById(inputid);
    if (divid == '' || !divobj) {
        alert('参数错误！');
        return;
    }
    if (inputobj.value == '') { alert('请输入意见!'); return; }
    Ext.Ajax.request({
      method:'post',
      url:'${ctx}/wf!saveTaskOpinion.action',
      params:{
        'instance.taskInstDbid': WF_CONFIG.taskInstDbid,
        'instance.handleComments': inputobj.value
      },
      success:function(){
        changeOpinion(inputobj.value, divobj);
        inputobj.value = '';
      },
      scope:this
    });
}

function changeOpinion(opinion, divobj) {
  var userOpinion = document.getElementById('userOpinion');
  if (userOpinion) {
    userOpinion.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
  } else {
    divobj.style.color = '#009966';
    divobj.innerHTML = opinion + '<br>&nbsp;&nbsp;&nbsp;&nbsp;${CurrUserName}&nbsp;&nbsp;' + new Date().format('yyyy-MM-dd hh:mm:ss');
  }
}

Ext.onReady(function(){
	$('input[type="checkbox"][name="sqsx"]').attr("disabled","disabled");
    var id_ = document.forms[0].id.value;
    //var acceptNo_ = document.forms[0].acceptNo.value;
    
    if (id_ == '') {
      if (Ext.getCmp('WF_PRINT')) Ext.getCmp('WF_PRINT').setDisabled(true);
    }
    var centerTabPanel = Ext.getCmp('centerPanel');
    
    var ywPanel = new Ext.TabPanel({
        id: 'YwRqInstallentinfoTpanel',
        renderTo: 'tpanel',
        border: false,
        activeTab: 0,
        height: centerTabPanel.getHeight(),
        enableTabScroll: true,
        defaults: {autoScroll: true},
        items: [
            //new Ext.Panel({title: '基本信息', tabCls: 'right-tab', contentEl: 'tpanel01', border: false}),
            //new Ext.Panel({title: '车辆信息列表', tabCls: 'right-tab', contentEl: 'tpanel06', border: false}),
            //new Ext.Panel({title: '收件材料', tabCls: 'right-tab', contentEl: 'sjcl_tpanel',border: false}),
            //new Ext.Panel({title: 'WEBGIS', tabCls: 'right-tab', contentEl: 'gis_tpanel',border: false})
        ],
        listeners: {
            remove: function(tp, c) {
                c.hide();
            },
            afterlayout: function(c) {
                c.strip.setWidth(c.stripWrap.getWidth() - 2);
            },
            tabchange : function (tpanel, p) {
            	if(p.title=="车辆信息列表")
            	{
					findByQyid();
            	}
            	if(p.title=="车辆检查表"){	
				   toCheckCar();
            	}
            }
        }
    });
    var cpbPanel = new Ext.Panel({id: 'cpbPanel', title: '呈批表', tabCls: 'right-tab', contentEl: 'tpanel02', border: false, disabled: id_ == '' ? true : false});
    var jbxxPanel = new Ext.Panel({title: '基本信息', tabCls: 'right-tab', contentEl: 'tpanel01', border: false});
    var clxxPanel = new Ext.Panel({id: 'clxxPanel', title: '车辆信息列表', tabCls: 'right-tab', contentEl: 'tpanel05', border: false, disabled: id_ == '' ? true : false});
    var checkcarPanel = new Ext.Panel({id: 'checkcarPanel', title: '车辆检查表', tabCls: 'right-tab', contentEl: 'checkcar', border: false, disabled: id_ == '' ? true : false});
       
       /**if (<wf:hasPriv activities="jbrsl,kzyj,fczyj,czyj,xcsh,jbryj2,kzyj2,fczsp,czsp,jbsj,ckjcyj,czgldsh,wfgldsh,wzgldsp,jbrsj,dzgz,czgldyqsh,wfgldyqsp,wzgldyqsh,jbrslyqbl" />) {//1
        ywPanel.add(new Ext.Panel({id: 'gisPanel', title: 'WEBGIS', tabCls: 'right-tab', contentEl: 'gis_tpanel', border: false, disabled: id_ == '' ? true : false}));
    }*/
    //if (<wf:hasPriv activities="cksa,jbryj,kzyj,fczyj,czyj,xcsh,jbryj2,kzyj2,fczsp,czsp,jbsj,ckjcyj,czgldsh,wfgldsh,wzgldsp,jbrsj,dzgz,czgldyqsh,wfgldyqsp,wzgldyqsh,jbrslyqbl" />) {//2
        ywPanel.add(new Ext.Panel({id: 'sjclPanel', title: '收件材料', tabCls: 'right-tab', contentEl: 'sjcl_tpanel', border: false, disabled: id_ == '' ? true : false}));
    //}
    //if (<wf:hasPriv activities="cksa,jbryj,kzyj,fczyj,czyj,xcsh,jbryj2,kzyj2,fczsp,czsp,jbsj,ckjcyj,czgldsh,wfgldsh,wzgldsp,jbrsj,dzgz,czgldyqsh,wfgldyqsp,wzgldyqsh,jbrslyqbl" />) {//1
        ywPanel.add(checkcarPanel);
        ywPanel.add(clxxPanel);
    //}
    //if (<wf:hasPriv activities="cksa,jbryj,kzyj,fczyj,czyj,xcsh,jbryj2,kzyj2,fczsp,czsp,jbsj,ckjcyj,czgldsh,wfgldsh,wzgldsp,jbrsj,dzgz,czgldyqsh,wfgldyqsp,wzgldyqsh,jbrslyqbl" />) {//2
        ywPanel.add(jbxxPanel);
    //}
    //if (<wf:hasPriv activities="jbryj,kzyj,fczyj,czyj,xcsh,jbryj2,kzyj2,fczsp,czsp,czgldsh,wfgldsh,wzgldsp,jbsj,dzgz,czgldyqsh,wfgldyqsp,wzgldyqsh,jbrslyqbl" />) {//2
   //     ywPanel.add(cpbPanel);
    //}
    //ywPanel.setActiveTab(jbxxPanel);
    //if (<wf:hasPriv activities="jbrsl,czgldsh,wfgldsh,wzgldsp,jbsj,dzgz,czgldyqsh,wfgldyqsp,wzgldyqsh,jbrslyqbl" />) {
    //    ywPanel.add(cpbPanel);
     //   ywPanel.setActiveTab(cpbPanel);
    //} else {
        //ywPanel.setActiveTab(jbxxPanel);
    //}
    
    if (<wf:hasPriv activities="jbryj,kzyj,fczyj,czyj,xcsh,jbryj2,czsp2,jbrslyqbl,kzyj2,fczsp,czsp,jbsj,ckjcyj" />) {
        ywPanel.add(cpbPanel);
        ywPanel.setActiveTab(cpbPanel);
    } else {
        //ywPanel.add(cpbPanel);
        ywPanel.setActiveTab(jbxxPanel);
    }
    ywPanel.doLayout(true);
    
});

</script>
</head>

<body>

<form action="yw-yn-ljzyz-shhz!save.action" method="post">
  <!---------------- 隐藏域区域 开始 ----------------->
   <input type="hidden" id="checkDate" value="<s:date name='checkCarDate' format="yyyy-MM-dd"/>" />
  <input type="hidden" id="checkPerson"  value="${checkCarPerson}" />
   <input type="hidden" id="checkLeader"  value="${checkCarLeader}" />
  <input type="hidden" id="hid" name="id" value="${id}" />
  <input id="pageNo" type="hidden"/>
  <input type="hidden" id="qyid" name="qyid" value="${qyid}" />
  <!---------------- 隐藏域区域 结束 ----------------->
  
<div id="tpanel"></div>

<div style="display:none">
<div id="tpanel01" align="center">
  <%@ include file="YwYnLjzyzShhz-sqb.jsp" %>
</div>

<div id="tpanel02" align="center">
  <%@ include file="YwYnLjzyzShhz-cpb.jsp" %>
</div>
<div id="tpanel04" align="center">
  <iframe src="${ctx}/flex/index.html" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
</div>
<div id="tpanel05">
	
</div>
<div id="tpanel06">
	<%@ include file="../../ywcmn/AddBus.jsp" %>
</div>
<div id="tpanel07">

</div>
<div id="checkcar" align="center">
	
</div>
<div id="gis_tpanel">
   <iframe src="${ctx}/flex/index.html" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
</div>
<div id="sjcl_tpanel">
  <iframe id="sjcl_iframe" src="${ctx}/yw-com-sjcllist!ywList.action?tplcode=${templateCode}&ajid=${id}&qyid=${qyid}" scrolling="auto" frameborder="0" width="100%" height="100%"></iframe>
</div>
</div>
</form>

<div style="display:none">
  <input id="attacheBrow" type="file" />
</div>
</body>
</html>
